<?php

//list($subdomain, $domain, $tld) = explode('.', $_SERVER['HTTP_HOST']);
//
//switch($subdomain){
//    case "actualites":
//        $highlight = "actualites";
//    break;
//    case 'partenaires':
//        $highlight = 'partenaires';
//        break;
//    case 'forum':
//        $highlight = 'forum';
//        break;
//    case 'photos':
//        $highlight = 'galerie photos';
//        break;
//    case 'videos':
//        $highlight = 'videos';
//        break;
//    case 'club':
//        $highlight = 'le club';
//        break;
//    case 'tennis-de-table':
//        $highlight = 'tennis de table';
//        break;
//    default:
//        $highlight = 'accueil';
//        break;
//}

$highlight = 'accueil';
switch($sf_context->getModuleName()){

    case 'main':
    case 'rss':
    case 'cgu':
    case 'sitemap':
    case 'event':
    case 'comment':
    case 'lastComments':
    case 'member':
        $highlight = 'accueil';
        break;
    case 'news':
        $highlight = 'actualites';
        break;
    case 'partner':
        $highlight = 'partenaires';
        break;
    case 'sfSimpleForum':
        $highlight = 'forum';
        break;
    case 'mediaPhoto':
        $highlight = 'galerie photos';
        break;
    case 'mediaVideo':
        $highlight = 'videos';
        break;
    case 'tmcContact':
    case 'findUs':
    case 'licensee':
    case 'team':
    case 'page': // page ici => bof bof (a cause des pages du footer s'il y en a plus tard)
        $highlight = 'le club';
        break;
    case 'scoringTable':
    case 'pointsCalculation':
    case 'matchType':
    case 'listClub':
        $highlight = 'tennis de table';
        break;
    default:
        $highlight = 'accueil';
        break;
}

$menu = new ioMenu();

$countMenuList = count($menu_list);
if(!empty($menu_list) && $countMenuList > 0 ) {
    $tabMenu = array();
    foreach($menu_list as $key => $cat) {
        if(!isset($menu[$cat[ 'title' ]]) && empty($cat[ 'category_parent_id' ])) {
            $tabMenu[] = array( "id" => $cat[ 'id' ], "title" => $cat[ 'title' ], "link" => $cat[ 'link' ]);
        }
    }

    foreach($menu_list as $key => $cat) {
        foreach($tabMenu as $key_parent => $cat_parent) {

            $link = url_for('@homepage') . $sf_user->getCulture() . $cat[ 'link' ];

            if(!isset($menu[$cat_parent["title"]])){
                $selected = (Utils::slugify($highlight) == Utils::slugify($cat_parent[ 'title' ]) ? " selected" : "");
                $menu->addChild($cat_parent[ 'title' ], (url_for('@homepage') . $sf_user->getCulture() . $cat_parent[ 'link' ]), array('class' => 'menu_level_0' . $selected));
            }

            if($cat[ 'category_parent_id' ] == $cat_parent["id"]) {
                $menu[$cat_parent["title"]]->addChild( '&#187; ' . $cat[ 'title' ], $link, array('class' => 'menu_level_1'));
            }
        }
    }
}

if($sf_user->isAuthenticated() && $sf_user->getGuardUser()->getIsSuperAdmin()){
    $menu->addChild('Admin', sfConfig::get('app_adminPage_uri'), array('class' => 'menu_level_0 admin'));
}

echo $menu->render();
?>